package com.bjsxt.exception3;

import java.util.Scanner;

/**
 * throw和throws的区别：
 *      1.作用
 *      2.位置
 *      3.数量
 */
public class TestException7 {

    public static void main(String[] args) {


        try {
            calculateAverageScore();
        } catch (NumberMinusException e) {
            e.printStackTrace();
        }

    }

    public static void calculateAverageScore() throws NumberMinusException {

        //1.输入总分
        System.out.println("请输入总分：");
        Scanner input = new Scanner(System.in);
        int totalScore = input.nextInt();

        //2.输入人数
        System.out.println("请输入人数：");
        int number = input.nextInt();

        //如果人数小于等于0，产生一个异常并抛出
        if (number <= 0) {
            //throw new RuntimeException("人数必须大于0：" + number);

            //throw new Exception("人数必须大于0：" + number);       //checked exception

            throw new NumberMinusException("人数必须大于0：" + number);
        }

        //3.计算平均分并输出
        int averageScore = totalScore / number;
        System.out.println("平均分：" + averageScore);

        System.out.println("计算完毕！");
        System.out.println("程序结束！");
    }
}
